package com.edu.exam.enums.curriculum;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 转换类型枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum TransitionType implements BaseEnum {
    MANUAL("MANUAL", "手动转换"),
    AUTOMATIC("AUTOMATIC", "自动转换"),
    SCHEDULED("SCHEDULED", "定时转换"),
    CONDITION_BASED("CONDITION_BASED", "条件转换"),
    EVENT_DRIVEN("EVENT_DRIVEN", "事件驱动"),
    APPROVAL_REQUIRED("APPROVAL_REQUIRED", "需要审批"),
    SYSTEM_INITIATED("SYSTEM_INITIATED", "系统发起"),
    USER_INITIATED("USER_INITIATED", "用户发起"),
    BATCH_OPERATION("BATCH_OPERATION", "批量操作"),
    EMERGENCY("EMERGENCY", "紧急转换");

    private final String code;
    private final String description;

    TransitionType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public static TransitionType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("TransitionType code cannot be null or empty");
        }
        for (TransitionType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown TransitionType code: " + code);
    }

    public static TransitionType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("TransitionType description cannot be null or empty");
        }
        for (TransitionType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown TransitionType description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}